package tw.com.diary.dao;

import java.util.List;

import tw.com.diary.db.domain.X0001;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class X0001DAO extends BaseDAO<String, X0001> {

	public final static String UUID = "uuid";
	public final static String YYYYMMDD = "yyyymmdd";
	public final static String CONTENT = "content";
	public final static String WEATHER = "weather";

	public X0001DAO(SQLiteDatabase conn) {
		super(conn);

	}

	public X0001 select(String id) {

		final Cursor cursor = this.conn.rawQuery(
				"select * from x0001 where uuid=?  ", new String[] { id });
		if (cursor.getCount() == 0) {
			return null;
		} else {
			return formCursor(cursor).get(0);
		}

	}

	public List<X0001> selectWithlimit() {
		final Cursor cursor = this.conn.rawQuery(
				"select * from x0001 ORDER BY yyyymmdd desc  limit 1000 ;", new String[] {});
		return this.formCursor(cursor);
	}

	public List<X0001> select() {
		final Cursor cursor = this.conn.rawQuery("select * from x0001 ",
				new String[] {});
		return this.formCursor(cursor);
	}

	public void deleteX001WhereQuery(String id) {
		this.conn.delete(x0001, "uuid=?", new String[] { id });
	}

	public void deleteX001WhereQuery(String... ids) {

		for (String id : ids) {
			this.deleteX001WhereQuery(id);

		}
	}

	public List<X0001> selectYyymmdd(String yyymmdd) {

		final String sql = "select * from x0001 where  yyyymmdd like ?";

		final Cursor cursor = this.conn.rawQuery(sql, new String[] {yyymmdd+"%"});
		return this.formCursor(cursor);

	}
	
	public List<X0001> selectByContent(String context) {

		final String sql = "select * from x0001 where  content like ?";

		final Cursor cursor = this.conn.rawQuery(sql, new String[] {"%"+context+"%"});
		return this.formCursor(cursor);
	}

	@Override
	public String[] getCoulumns() {

		return new String[] { UUID, YYYYMMDD, CONTENT };
	}

	@Override
	public Class<X0001> getMyClass() {

		return X0001.class;
	}

}
